package com.jt.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class CrossConfig extends WebMvcConfigurationSupport {
    @Override
    protected void addCorsMappings(CorsRegistry registry) {
        CorsRegistration corsRegistration = registry.addMapping("/**");
        corsRegistration.allowCredentials(true); // 是否发送 Cookie
        corsRegistration.allowedOriginPatterns("*"); // 支持域
        corsRegistration.allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"});// 支持方法
        corsRegistration.allowedHeaders("*");
        corsRegistration.exposedHeaders("*");
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //直接可以去本地拿。上传图片后。不用重新启动就直接可以回显
        registry.addResourceHandler("/static/**").addResourceLocations("file:C:\\Users\\366064537\\Desktop\\自研\\fuxi_zhiyu\\src\\main\\resources\\static\\img");
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {

    }

}
